<!--措施清单-->
<template>
  <Layout>
    <Form ref="queryForm" :model="dataToQuery" :label-width="120">
      <Row class="query-form">
        <Col span="8">
          <FormItem label='整改进度：'>
            <Select   v-model="dataToQuery.progress"
                    :label-in-value="true" placeholder="请选择整改进度" clearable = 'true'>
              <Option v-for="item in progressList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">

        </Col>


        <Col offset="8" span="8" v-if="!switchFlag">
<!--          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>-->
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
        <Col span="8" v-else>
          <FormItem label='隐患分类：'>
            <Cascader  :data="areaTree" v-model="dataToQuery.dangerSortArr" change-on-select :transfer="true"
                      @on-change="(value,selectedData)=>{$set(dataToQuery,'dangerSort',value.join(','))}"></Cascader>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='整改责任人：' prop='persionHeld'>
            <Input  class='' placeholder="请填写整改责任人" type='text' v-model='dataToQuery.persionHeld'></Input>
          </FormItem>
        </Col>


      </Row>
      <Row v-show="switchFlag" class="query-form">

        <Col span="8" :offset="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <Button type="primary" class="ivu-btn-add" :loading="buttonLoading" icon="md-cloud-download"
                  @click="downloadFile">导出
          </Button>
          <Button size="large" class="ivu-btn-add" icon="md-home" @click="back">返回</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
           :loading='pageStatus.loading ||  pageStatus.baseLoading'
           border :columns="columns1" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer
              show-elevator/>
      </Col>
    </Row>
    <Modal :mask-closable="false" :title="mode == 'view' ?'落实情况详情':'落实情况'" :transfer=false v-model="dialogShow" v-if="dataToView && dialogShow"
           :width=800 :styles="{height:'559px'}" class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dataToView" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false"
                :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='隐患问题名称：' prop='dangerName'>
                  <div v-if="mode === 'view'">{{ dataToView.dangerName }}</div>
                  <Input readonly v-else class='' placeholder="请填写隐患问题名称" type='text' v-model='dataToView.dangerName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='整改进度：' prop='progress'>
                  <div v-if="mode === 'view'">{{ dataToView.progressName }}</div>
                  <Select v-else  v-model="dataToView.progress"
                          :label-in-value="true" placeholder="请选择整改进度" clearable = 'true'>
                    <Option v-for="item in progressList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>

              </Col>

            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填报人：' prop='createUserName' >
                  <div v-if="mode === 'view'">{{ dataToView.createUserName }}</div>
                  <Input readonly v-else class='' placeholder="请填写隐患问题名称" type='text' v-model='dataToView.createUserName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='填报日期：' prop='createDate'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.createDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择填报日期" v-model='dataToView.createDate'  :readonly="true"></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='落实时间：' prop='implementationDate'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.implementationDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择落实时间" v-model='dataToView.implementationDate' ></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">

              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='情况描述：' >
                  <div v-if="mode === 'view'">{{ dataToView.impDesc }}</div>
                  <Input v-else class=''placeholder="请填写情况描述" type='textarea' v-model='dataToView.impDesc'></Input>
                </FormItem>
              </Col>
            </Row>

          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dataToView')">确定</Button>
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal>

  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import {sessionStorage} from '@/common/cacheUtils.js';
import {formatDate} from '@/tools/index'
import pageCommonFunction from '@/components/pageCommonFunction.js'

var cascaderDom = () => import('@/components/cascader-dom.vue');
export default {
  components: {
    cascaderDom
  },
  data() {
    return {
      ...this.createCommonDataField(),
      switchFlag: false,
      uploadFile:null,
      buttonLoading1:false,
      importModal:false,
      token:sessionStorage('token').get('Authorization'),
      columns1: [
        { title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        { key:'dangerName',title: '隐患问题名称',  align: 'center',minWidth: 120 },
        { key:'progressName',title: '整改进度',  align: 'center',minWidth: 120 },
        { key:'implementationDate',title: '落实时间',  align: 'center',minWidth: 120,render: this.renderCellDate },
        { key:'impDesc',title: '情况描述',  align: 'center',minWidth: 120,tooltip:true },
        { key:'createUserName',title: '创建人',  align: 'center',minWidth: 120 },
        { key:'createDate',title: '创建时间',  align: 'center',minWidth: 120,render: this.renderCellDate },
        this.getActionColumns()
      ],
      upUrl:Api.uploadDangerList,
      ruleCustom: {
        dangerName: [ { required: true, message: '请填写隐患问题名称', trigger: 'change',}],
        progress: [ { required: true, message: '请选择整改进度', trigger: 'change',}],
        implementationDate: [ { required: true, message: '请填写落实时间', trigger: 'change',type:'date'}],
        impDesc: [ { required: true, message: '请填写情况描述', trigger: 'change',}],


      },
      tableHeight: 10,
      progressList:[],
      // api
      standardSelectModal: false,
      queryUrl: Api.queryImplementation,
      deleteUrl: Api.deleteImplementation,
      updateUrl: Api.updateImplementation,
      saveUrl: Api.saveImplementation,
      buttonLoading: false,
      dangerModel:false,
      danger:null,
    }
  },
  async mounted() {
    let _this = this;
    this.dataToQuery = {};
    this.setTableHeight();
    this.pageStatus.baseLoading = true;
    this.$http.get(Api.queryCodeDetailBySortId + '/DL-00004', {params: {}}).then((res) => {
      _this.progressList = res.data.data
    });
    this.danger = this.$route.query;
    this.pageStatus.baseLoading = false
    this.query();
  },
  methods: {

    ...pageCommonFunction,
    openDangerModal(){
      this.dangerModel = true;
    },
    selectDanger(row){
      this.dangerModel = false;
      this.dataToView.dangerId = row.id;
      this.dataToView.dangerName = row.dangerName;
    },
    dictListToMap(arr, key = 'codingCodeId') {
      var map = {}
      arr.map(item => {
        map[item[key]] = item
      })
      return map
    },

    downloadMod(){
      this.buttonLoading1 = true
      this.$http.get(Api.downloadImplementation, {
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "落实情况.xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading1 = false
      })
    },
    importDanger(){
      this.importModal = true;
    },

    uploadExcel(response, file, fileList){
      //上传完成后执行代码
      if (response.status === 200) {
        this.$Message.success('导入成功');
        this.query()
      } else if (response.status === 201) {
        this.$Message.error("导入失败");
        this.query()
      }
    },
    deleteData(params) {
      this.deleteDateAjax(params);
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 44;

      } else {
        this.tableHeight = this.tableHeight - 44;
      }

    },
    setOrgId(data) {
      this.dataToQuery.companyId = data[data.length - 1];
    },
    setOrgName(data) {

    },
    query() {
      this.dataToQuery.dangerId = this.danger.id;
      this.queryAjax()
    },
    back() {
      this.$router.push('/DangerList')
    },
    submit(name) {

      this.submitAjax(name);
    },
    createEmptyDataToAdd() {
      return {
        dangerName:this.danger.dangerName,
        dangerId:this.danger.id,
        createDate:new Date()
      }
    },
    downloadFile() {
      this.buttonLoading = true
      this.$http.get(Api.downloadImplementation, {
        params: this.dataToQuery,
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "落实情况(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading = false
      })
    },
  },
  watch: {},

}
</script>

<style lang='css' scoped>
@import '../../../index.css';

.importDanger{
  display:inline-block
}
</style>
